// 用于主页面通用内容
import Main from '@/views/main.vue';

// 引用各模块路由
import goods from './modules/goods.js';
import order from './modules/order.js';
import user from './modules/user.js';
import stock from './modules/stock.js';
import finance from './modules/finance.js';
import statistics from './modules/statistics.js';
import shop from './modules/shop.js';

import app from './modules/app.js';
import setup from './modules/setup.js';
import cashier from './modules/cashier.js';
import service from './modules/service.js';

// 引用市场模块路由
import market from './market/index.js';

/*
 * meta 参数说明
 * @params	string	title	页面标题
 * @params	boolean	cache	是否通过router-view的keep-alive缓存页面
 * @params	boolean access	权限，需自行写相关业务逻辑
 * @params	boolean divider 用于二级菜单时是否显示分割线，仅为false时生效
 * @params	string	active	用于菜单显示重新指向对应的节点
 * 
 */

/*
 * unLoginRouter 说明
 * 1.未登录状态下可访问的独立页面
 * 
 */
export const unLoginRouter = [
	{
        path: '/login',
        name: 'login',
        meta: {
            title: '登录'	
        },
        component: resolve => {
        	require(['@/views/login/login.vue'], resolve)
        }
    }
]

/*
 * simpleRouter 简单路由说明
 * 1.登录状态下可访问的独立页面
 * 
 */
export const simpleRouter = [
	{
		path: '/404',
		name: 'error-404',
		meta: {
			title: '404 页面不存在'
		},
		component: resolve => {
			require(['@/views/error/404.vue'], resolve)
		}
	},
	{
		path: '/wechat_empower',
		name: 'wechat_empower',
		meta: {
			title: '微信授权'
		},
		component: resolve => {
			require(['@/views/setup/wechat/login/empower.vue'], resolve)
		}
	}
]

/*
 * mainRouter 说明
 * 1.需登录后才可访问的路由
 * 2.需要通过main通用组件显示的路由
 * 3.不需要在主菜单显示的路由
 * 
 */
export const mainRouter = {
	path: '/',
	name: 'mainRouter',
	redirect: '/home',		// 将/重置到/home主页
	component: Main,
	children: [
    	
	]
}

// 应用市场路由
export const marketRouter = market;

/*
 * appRouter 说明
 * 1.需登录后才可访问的路由
 * 2.需要通过main通用组件显示的路由
 * 3.需要展示在主菜单里的路由，支持多级，3级及以上的路由需要通过RouterView来加载
 * 
 */
export const appRouter = [
	// 如果首页不需要展示在主菜单里，可放在mainRouter里
	{
		path: '/home',
		name: 'home',
		redirect: '/home/index',
		meta: {
			title: '全局',
			icon: 'ios-analytics'
		},
        component: Main,
        children: [
        	{
        		path: 'index',
	        	name: 'home_index',
	        	meta: {
	        		title: '全局',
					cache: true
	        	},
	        	component: resolve => {
		        	require(['@/views/home/index.vue'], resolve)
		        }
        	}
        ]
	},
	goods,
	order,
	user,
	stock,
	finance,
	statistics,
	shop,
	app,
	setup,
	cashier,
	service
]

// 所有上面定义的路由都要写在下面的routers里
export const routers = [
	...unLoginRouter,
    ...simpleRouter,
    ...appRouter,
    marketRouter
];